package DBUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBConnection {
	static Connection connection;
	static String url,username,password,DriverClass;
	static{
		DriverClass="com.mysql.jdbc.Driver";
		url="jdbc:mysql://localhost/db_vote";
		username="root";
		password="password";
	}
	
	static public Connection getConnection(){
	
		try {
			Class.forName(DriverClass);
			connection =DriverManager.getConnection(url,username,password);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return connection;
	}
	
	static public void closeConnection(Connection connection) throws SQLException{
		if (connection!=null) {
			connection.close();
		}
	}
	static public void closeStatement(Statement statement) throws SQLException{
		if (statement!=null) {
			statement.close();
		}
	}
	static public void closeResultSet(ResultSet resultSet) throws SQLException{
		if (resultSet!=null) {
			resultSet.close();
		}
	}
}
